package com.cysyz.web.modules.base.permission.tag;

import com.cysyz.web.modules.base.permission.service.PermissionService;
import com.cysyz.web.modules.base.support.ServletActionContext;
import com.cysyz.web.modules.base.support.SysConstants;
import com.cysyz.web.modules.base.user.domain.SysUser;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

/**
 * Created by cuiyong on 15/1/24.
 */
public class PermissionChooseTag extends SimpleTagSupport{
    private PermissionService permissionService;
    private SysUser currentLoginUser = (SysUser) ServletActionContext.getRequest().getSession().getAttribute(SysConstants.CURRENT_LOGIN_SYSUSER);
    private boolean checkPass;

    public PermissionChooseTag() {
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getRequest().getServletContext());
        permissionService = (PermissionService) wac.getBean("permissionService");
    }

    @Override
    public void doTag() throws JspException, IOException {
        getJspBody().invoke(null);
    }

    public PermissionService getPermissionService() {
        return permissionService;
    }

    public SysUser getCurrentLoginUser() {
        return currentLoginUser;
    }

    public boolean isCheckPass() {
        return checkPass;
    }

    public void setCheckPass(boolean checkPass) {
        this.checkPass = checkPass;
    }
}
